package com.example.demo2.common.config.web;

import lombok.Data;

@Data
public class WLResult<T> {


    public T data;

    public Integer code;

    public String msg;


    /**
     * 响应成功
     * @param date
     * @return
     * @param <D>
     */
    public static <D> WLResult<D>  success(D date){
        WLResult<D> result = new WLResult<>();
        result.setData(date);
        result.setCode(10000);
        result.setMsg("成功");
        return result;
    }


    /**
     * 响应失败
     * @param
     * @return
     * @param <D>
     */
    public static  <D> WLResult<D>  error(ErrorEnum errorEnum){
        WLResult<D> result = new WLResult<>();
        result.setData(null);
        result.setCode(errorEnum.getCode());
        result.setMsg(errorEnum.getMsg());
        return result;
    }

    public static  <D> WLResult<D>  error(String msg, Integer code){
        WLResult<D> result = new WLResult<>();
        result.setData(null);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}
